package models;

import com.avaje.ebean.Ebean;
import com.avaje.ebean.Model;
import com.avaje.ebean.SqlUpdate;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import play.data.format.Formats;
import play.data.validation.Constraints;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.*;

/**
 * Customer entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "customer")
public class Customer extends Model {

    @Id
    @Constraints.Min(10)
	public Long customerId;

    @Formats.NonEmpty
	public String name;

    @Constraints.Required
    @Formats.NonEmpty
	public String sex;

	public String address;

    @Formats.DateTime(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date birthday;

	public String isvip;

    @Formats.NonEmpty
	public String phone;

    public String passwd;

    @Formats.DateTime(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date createtime = new Date();

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "customer")
    @JsonBackReference
    public Set<Bill> bill = new HashSet<Bill>(0);

    public static Model.Finder<Long, Customer> find = new Model.Finder<>(Customer.class);

    public static List<Customer> all() {
        return find.all();
    }

}